<template>
  <div>
    <avue-crud v-show="page.total > 0"
               :option="option"
               :table-loading="loading"
               :data="data"
               :page.sync="page"
               @current-change="currentChange"
               @size-change="sizeChange"
               @on-load="onLoad">
    </avue-crud>
  </div>
</template>

<script>
import {getCustomerOfferList} from "@/api/business/offer";
import {mapGetters} from "vuex";
import store from '@/store'
import {getSysDictList} from "@/api/system/dict";
import {findObject} from "@/util/util";

export default {
  name: 'customerOfferList',
  props: {
    customerId: {
      type: String,
    },
  },
  data() {
    return {
      query: {},
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      statusList: [
        {label: '草稿', value: 0},
        {label: '活跃', value: 1},
        {label: '停止', value: 2},
        {label: '删除', value: 3},
      ],
      option: {
        tip: false,
        searchShow: false,
        border: true,
        index: false,
        viewBtn: false,
        editBtn: false,
        addBtn: false,
        delBtn: false,
        selection: false,
        menu: false,
        columnBtn: false,
        refreshBtn: false,
        column: [
          {
            label: "订单名称",
            prop: "name",
          },
          {
            label: "订单ID",
            prop: "id",
          },
          {
            label: "状态",
            prop: "status",
            type: 'select',
            dicData: [
              {label: '草稿', value: 0},
              {label: '活跃', value: 1},
              {label: '停止', value: 2},
              {label: '删除', value: 3}
            ],
          },
          {
            label: "创建时间",
            prop: "createTime",
          },
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["userInfo"]),
  },
  created() {
  },
  mounted() {
  },

  methods: {
    //table 状态
    statusTableList() {
      return [
        {label: '草稿', value: 0, disabled: true},
        {label: '活跃', value: 1},
        {label: '停止', value: 2}
      ]
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    onLoad(page, params = {}) {
      if(this.customerId == null) {
        this.page.total = 0;
        this.data = [];
        return;
      }
      this.loading = true;
      this.query.customerId = this.customerId;
      this.query.offerTypeList = "admin,owner,manager,shared";
      getCustomerOfferList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
    }
  }
};
</script>

<style scoped>
  /deep/.avue-crud__menu {
    min-height: 0px;
  }
</style>
